/**
 * Created by seikann on 2017-10-10.
 */
// Schema、Model、Entity或者Documents的关系请牢记，Schema生成Model，Model创造Entity，Model和Entity都可对数据库操作造成影响，但Model比Entity更具操作性。
const mongoose = require('mongoose');
// 连接数据库 如果不自己创建 默认test数据库会自动生成
mongoose.connect('mongodb://localhost/test');

// 为这次连接绑定事件
const db = mongoose.connection;
db.once('error', () => console.log('Mongo connection error'));
db.once('open', () => console.log('Mongo connection successed'));
/************** 定义模式loginSchema **************/
const loginSchema = mongoose.Schema({
  userName: String,
  password: String
});
const personInfoSchema = mongoose.Schema({
  userName: String, //用户名
  userType: String, //用户类型
  nickName: String, //昵称
  phone: Number, //联系电话
  email: String, //邮箱
  intro: String  //简介
});

const articlePublishSchema = mongoose.Schema({
  title: String,
  type: String,
  publish: Boolean,
  content: String
});

/************** 定义模型Model **************/
const Models = {
  Login: mongoose.model('Login', loginSchema),
  perInfo: mongoose.model('perInfo', personInfoSchema),
  articlePublish: mongoose.model('articlePublish', articlePublishSchema)
}

module.exports = Models;
